//逐字节读取
// Created by 123 on 2024/12/27.
//
#include "stdio.h"

int mainc077(){
    FILE* fp;
    char data[] = "hello , binary!";
    size_t dataSize = sizeof(data);//包含了终止符\0
    //写入二进制文件
    fp = fopen("bytetext.bin","wb");
    if(fp == NULL){
        perror("open error\n");
        return 1;
    }

    fwrite(data,sizeof(char),dataSize,fp);
    fclose(fp);

    printf("byte has been writed in file!\n");

    //读取二进制
    fp = fopen("bytetext.bin","rb");
    if(fp == NULL){
        perror("open error\n");
        return 1;
    }

    char buffer[100];
    fread(buffer,sizeof(char),dataSize,fp) ;
    fclose(fp);
    printf("read result:%s\n",buffer);


    return 0;
}